package org.jsoft.panel;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class Test extends JFrame {
	public Test() {
		super();
		CirclePanel panel = new CirclePanel();
		add(panel, "Center");
		setSize(500, 500);
		setVisible(true);
		

		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		
	}

	public static void main(String[] args) {
		new Test();
	}

	class CirclePanel extends JPanel {
		public static final double PI = Math.PI;
		private int degree = 180;
		private int axisx;
		private int axisy;

		public CirclePanel() {
			setSize(500, 500);
			axisx = getWidth() / 2;
			axisy = getHeight() / 2;
			setVisible(true);
			Timer timer = new Timer(10, new TimerListener());
			timer.start();
		}

		@Override
		protected void paintComponent(Graphics g) {
			super.paintComponent(g);
			g.fillRect(axisx, axisy, 2, 2);
			g.drawOval((int) (axisx - 100 + 5), (int) (axisy - 100 + 5), 200,
					200);
			int x=-(int) (100 * Math.sin(PI * degree / 180)) + axisx;
			int y=(int) (100 * Math.cos(PI * degree / 180)) + axisy;
			g.fillOval(x,y
					, 10, 10);

		}

		class TimerListener implements ActionListener {
			public void actionPerformed(ActionEvent e) {
				degree += 1;
				repaint();
			}
		}
	}
}
